//
//  ChangePassWordController.m
//  pmmSS
//
//  Created by Mac book on 2017/9/20.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "ChangePassWordController.h"


@interface ChangePassWordController ()<UITextFieldDelegate>

@property (nonatomic,strong) NSArray *dataArray;

@property (nonatomic,strong) NSString *old_password;
@property (nonatomic,strong) NSString *New_one_password;
@property (nonatomic,strong) NSString *New_two_password;

@end



@implementation ChangePassWordController


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [self setUpNavBar];

}
-(void)viewDidLoad{

    [super viewDidLoad];

    [self setTableView:self.tableView];

    _dataArray = @[@"您的密码",@"新密码",@"重复密码"]
                   ;

}
-(void)setUpNavBar{


    UILabel *title_label = [HMLabel createLabelWithText:@"修改密码" andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(20)] andTextAlignment:NSTextAlignmentCenter];

    title_label.frame = CGRectMake(0, 0, 100, 35);

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bgimage"] forBarMetrics:UIBarMetricsDefault];

    self.navigationItem.titleView = title_label;

// TODO :导航左按钮

    UIButton *leftBtn = [HMButton createButtonWithTitle:@"" andTitleColor:nil andBgColor:nil andImage:[UIImage imageNamed:@"icon_arrow_left_white"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:101];
    leftBtn.frame = CGRectMake(0, 0, autoScaleW(60), autoScaleW(30));
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(autoScaleH(7), 0, autoScaleH(7), autoScaleW(50))];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];

    [self.navigationItem setLeftBarButtonItem:leftItem];
// TODO :导航右按钮
    UIButton *rightBtn = [HMButton createButtonWithTitle:@"确定" andTitleColor:[UIColor whiteColor] andBgColor:nil andImage:nil andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:102];
    rightBtn.frame = CGRectMake(0, 0, 70, 30);
    rightBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 30, 0, 0);
    rightBtn.titleLabel.font = [UIFont fontWithName:default_fontname size:autoScaleW(16)];

    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    [self.navigationItem setRightBarButtonItem:rightItem];

}

-(void)setTableView:(UITableView *)tableView{

    tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];

}

#pragma mark : UITableViewDelegate  &&   UITableViewDataSource


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString * cellID = @"UITableViewCell" ;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;




        UILabel *label = [HMLabel createLabelWithText:_dataArray[indexPath.section] andTextColor:RGBA(51,51,51,1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(14)] andTextAlignment:NSTextAlignmentLeft];

        [cell.contentView addSubview:label];


        [label mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(cell);
            make.left.mas_equalTo(autoScaleW(20));

            make.height.mas_equalTo(autoScaleH(17));

            make.width.mas_equalTo(autoScaleW(60));
            
        }];

        UITextField *textfield  = [HMTextField createTextFieldWithText:@"" andpLlaceholder:nil andTextColor:RGBA(51,51,51,1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(14)] andTextAlignment:NSTextAlignmentLeft andTextFieldViewMode:UITextFieldViewModeAlways];
        textfield.tag = indexPath.section;
        textfield.delegate = self;

        [textfield addTarget:self action:@selector(changedTextField:) forControlEvents:UIControlEventEditingChanged];

        [cell.contentView addSubview:textfield];


        [textfield mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(cell);
            make.left.mas_equalTo(autoScaleW(80));

            make.height.mas_equalTo(autoScaleH(17));

            make.width.mas_equalTo(autoScaleW(200));
            
        }];


    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{


    return section == 0?10.f:1;

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return autoScaleH(50);
}


-(void)clickButton:(UIButton *)button{

    switch (button.tag) {
        case 101:
        {

        [self.navigationController popViewControllerAnimated:YES];

        }
            break;

        case 102:
        {

        }
            break;


        default:
            break;
    }

    
    
}

#pragma mark -给每个cell中的textfield添加事件，只要值改变就调用此函数
-(void)changedTextField:(id)sender
{
    UITextField *tempTextField = (UITextField *)sender;
   // NSLog(@"tag------%ld;值是---%@",tempTextField.tag,tempTextField.text);

    if (tempTextField.tag == 0) {
        _old_password = tempTextField.text;
    }else if (tempTextField.tag == 1){
        _New_one_password = tempTextField.text;
    }else if(tempTextField.tag == 2){
        _New_two_password = tempTextField.text;
    }


   // NSLog(@"_old_password值是---%@",_old_password);
}

- (void)textFieldDidEndEditing:(UITextField *)textField{


    if (_New_one_password != nil && _New_two_password != nil) {

        if ([_New_one_password isEqualToString:_New_two_password]) {

            NSLog(@"两次密码一致");
        }else{
            NSLog(@"请重新输入");
            
        }
    }



}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
